'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
    return typeof obj;
} : function (obj) {
    return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};

exports.default = {
    LoginUtils: {
        checkLogin: function (successCallback, loginCallback) {
            var me = this;
            if (wx.getExtConfig) {
                wx.getExtConfig({
                    success: function (res) {
                        console.log(res.extConfig);
                        me.checkSession(res.extConfig, successCallback);
                    }
                });
            } else {
                me.checkSession({}, successCallback, loginCallback);
            }
        },

        checkSession: function (extConfig, successCallback, loginCallback) {
            var me = this;
            wx.checkSession({
                success: function () {
                    //session_key 未过期，并且在本生命周期一直有效
                    if (successCallback != null && typeof successCallback === 'function') {
                        successCallback();
                    }
                },
                fail: function () {
                    // session_key 已经失效，需要重新执行登录流程
                    wx.login({
                        success: function (response) {
                            var code = response.code;
                            if (loginCallback != null && typeof loginCallback === 'function') {
                                loginCallback(code);
                            }
                        }
                    });//重新登录
                }
            });
        }
    }
};